home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / man / catn / text.n < prev    next >
Text File  |  1994-09-20  |  44KB  |  1,057 lines

  1.  
  2.  
  3.  
  4. text(n)                    Tk Commands
  5.  
  6.  
  7.  
  8. _________________________________________________________________
  9.  
  10. NAME
  11.      text - Create and manipulate text widgets
  12.  
  13. SYNOPSIS
  14.      text _p_a_t_h_N_a_m_e ?_o_p_t_i_o_n_s?
  15.  
  16. STANDARD OPTIONS
  17.      background      foreground     insertWidth     selectBorderWidth
  18.      borderWidth     insertBackground               padXselectForeground
  19.      cursor          insertBorderWidth              padYsetGrid
  20.      exportSelection insertOffTime  relief          yScrollCommand
  21.      font            insertOnTime   selectBackground
  22.  
  23.      See the ``options'' manual entry for details on the standard
  24.      options.
  25.  
  26. WIDGET-SPECIFIC OPTIONS
  27.      Name:           height
  28.      Class:          Height
  29.      Command-Line Switch:           -height
  30.  
  31.           Specifies the desired height for the window,  in  units
  32.           of characters.  Must be at least one.
  33.  
  34.      Name:           state
  35.      Class:          State
  36.      Command-Line Switch:           -state
  37.  
  38.           Specifies one of two states for the  text:   normal  or
  39.           disabled.   If the text is disabled then characters may
  40.           not be inserted or deleted and no insertion cursor will
  41.           be displayed, even if the input focus is in the widget.
  42.  
  43.      Name:           width
  44.      Class:          Width
  45.      Command-Line Switch:           -width
  46.  
  47.           Specifies the desired width for the window in units  of
  48.           characters.   If  the font doesn't have a uniform width
  49.           then the width  of  the  character  ``0''  is  used  in
  50.           translating from character units to screen units.
  51.  
  52.      Name:           wrap
  53.      Class:          Wrap
  54.      Command-Line Switch:           -wrap
  55.  
  56.           Specifies how to handle lines in the text that are  too
  57.           long  to  be  displayed  in a single line of the text's
  58.           window.  The value must be none or  char  or  word.   A
  59.           wrap  mode of none means that each line of text appears
  60.  
  61.  
  62.  
  63. Tk                                                              1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. text(n)                    Tk Commands
  71.  
  72.  
  73.  
  74.           as exactly one line on the  screen;   extra  characters
  75.           that don't fit on the screen are not displayed.  In the
  76.           other modes each line of text will be  broken  up  into
  77.           several screen lines if necessary to keep all the char-
  78.           acters visible.  In char mode a screen line  break  may
  79.           occur  after  any  character; in word mode a line break
  80.           will only be made at word boundaries.
  81. _________________________________________________________________
  82.  
  83.  
  84. DESCRIPTION
  85.      The text command creates a new window (given by the _p_a_t_h_N_a_m_e
  86.      argument)  and  makes  it  into  a  text widget.  Additional
  87.      options, described above, may be specified  on  the  command
  88.      line  or  in the option database to configure aspects of the
  89.      text such as its default background color and  relief.   The
  90.      text command returns the path name of the new window.
  91.  
  92.      A text widget displays one or more lines of text and  allows
  93.      that  text  to  be  edited.  Text widgets support three dif-
  94.      ferent kinds of annotations on the text, called tags, marks,
  95.      and  windows.   Tags allow different portions of the text to
  96.      be displayed with different fonts and colors.  In  addition,
  97.      Tcl  commands  can  be associated with tags so that commands
  98.      are invoked when particular actions such as  keystrokes  and
  99.      mouse button presses occur in particular ranges of the text.
  100.      See TAGS below for more details.
  101.  
  102.      The second form of annotation consists of marks,  which  are
  103.      floating  markers in the text.  Marks are used to keep track
  104.      of various interesting  positions  in  the  text  as  it  is
  105.      edited.  See MARKS below for more details.
  106.  
  107.      The third form of annotation allows arbitrary windows to  be
  108.      displayed  in  the  text widget.  See WINDOWS below for more
  109.      details.
  110.  
  111.  
  112. INDICES
  113.      Many of the widget commands  for  texts  take  one  or  more
  114.      indices as arguments.  An index is a string used to indicate
  115.      a particular place within a text, such as a place to  insert
  116.      characters  or  one  endpoint  of  a  range of characters to
  117.      delete.  Indices have the syntax
  118.  
  119.           _b_a_s_e _m_o_d_i_f_i_e_r _m_o_d_i_f_i_e_r _m_o_d_i_f_i_e_r ...
  120.  
  121.      Where _b_a_s_e gives a starting point and the  _m_o_d_i_f_i_e_rs  adjust
  122.      the  index  from  the  starting  point (e.g. move forward or
  123.      backward one character).  Every index must contain  a  _b_a_s_e,
  124.      but the _m_o_d_i_f_i_e_rs are optional.
  125.  
  126.  
  127.  
  128.  
  129. Tk                                                              2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. text(n)                    Tk Commands
  137.  
  138.  
  139.  
  140.      The _b_a_s_e for an index must have one of the following forms:
  141.  
  142.      _l_i_n_e._c_h_a_r   Indicates _c_h_a_r'th character on line _l_i_n_e.  Lines
  143.                  are  numbered  from 1 for consistency with other
  144.                  UNIX programs that use  this  numbering  scheme.
  145.                  Within a line, characters are numbered from 0.
  146.  
  147.      @_x,_y        Indicates the character that  covers  the  pixel
  148.                  whose x and y coordinates within the text's win-
  149.                  dow are _x and _y.
  150.  
  151.      end         Indicates the last character in the text,  which
  152.                  is always a newline character.
  153.  
  154.      _m_a_r_k        Indicates the  character  just  after  the  mark
  155.                  whose name is _m_a_r_k.
  156.  
  157.      _t_a_g.first   Indicates the first character in the  text  that
  158.                  has  been  tagged with _t_a_g.  This form generates
  159.                  an error if no characters are  currently  tagged
  160.                  with _t_a_g.
  161.  
  162.      _t_a_g.last    Indicates the character just after the last  one
  163.                  in the text that has been tagged with _t_a_g.  This
  164.                  form generates an error  if  no  characters  are
  165.                  currently tagged with _t_a_g.
  166.  
  167.      If modifiers follow the base index, each one  of  them  must
  168.      have  one of the forms listed below.  Keywords such as chars
  169.      and wordend may be abbreviated as long as  the  abbreviation
  170.      is unambiguous.
  171.  
  172.      + _c_o_u_n_t chars
  173.           Adjust the index forward by _c_o_u_n_t characters, moving to
  174.           later  lines  in  the  text if necessary.  If there are
  175.           fewer than _c_o_u_n_t  characters  in  the  text  after  the
  176.           current index, then set the index to the last character
  177.           in the text.   Spaces  on  either  side  of  _c_o_u_n_t  are
  178.           optional.
  179.  
  180.      - _c_o_u_n_t chars
  181.           Adjust the index backward by _c_o_u_n_t  characters,  moving
  182.           to  earlier  lines  in the text if necessary.  If there
  183.           are fewer than _c_o_u_n_t characters in the text before  the
  184.           current  index, then set the index to the first charac-
  185.           ter in the text.  Spaces on either side  of  _c_o_u_n_t  are
  186.           optional.
  187.  
  188.      + _c_o_u_n_t lines
  189.           Adjust the index forward by _c_o_u_n_t lines, retaining  the
  190.           same  character position within the line.  If there are
  191.           fewer than _c_o_u_n_t lines after the  line  containing  the
  192.  
  193.  
  194.  
  195. Tk                                                              3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. text(n)                    Tk Commands
  203.  
  204.  
  205.  
  206.           current  index, then set the index to refer to the same
  207.           character position on the last line of the text.  Then,
  208.           if  the  line is not long enough to contain a character
  209.           at the indicated character position, adjust the charac-
  210.           ter position to refer to the last character of the line
  211.           (the newline).  Spaces on  either  side  of  _c_o_u_n_t  are
  212.           optional.
  213.  
  214.      - _c_o_u_n_t lines
  215.           Adjust the index backward by _c_o_u_n_t lines, retaining the
  216.           same  character position within the line.  If there are
  217.           fewer than _c_o_u_n_t lines before the line  containing  the
  218.           current  index, then set the index to refer to the same
  219.           character position on  the  first  line  of  the  text.
  220.           Then, if the line is not long enough to contain a char-
  221.           acter at the indicated character position,  adjust  the
  222.           character  position  to  refer to the last character of
  223.           the line (the newline).  Spaces on either side of _c_o_u_n_t
  224.           are optional.
  225.  
  226.      linestart
  227.           Adjust the index to refer to the first character on the
  228.           line.
  229.  
  230.      lineend
  231.           Adjust the index to refer to the last character on  the
  232.           line (the newline).
  233.  
  234.      wordstart
  235.           Adjust the index to refer to the first character of the
  236.           word  containing the current index.  A word consists of
  237.           any number of adjacent  characters  that  are  letters,
  238.           digits,  or  underscores, or a single character that is
  239.           not one of these.
  240.  
  241.      wordend
  242.           Adjust the index to refer to the character  just  after
  243.           the  last one of the word containing the current index.
  244.           If the current index refers to the  last  character  of
  245.           the text then it is not modified.
  246.  
  247.      If more than one modifier is present then they  are  applied
  248.      in  left-to-right  order.   For example, the index ``end - 1
  249.      chars'' refers to the next-to-last character in the text and
  250.      ``insert  wordstart  -  1  c''  refers to the character just
  251.      before the first one in the word  containing  the  insertion
  252.      cursor.
  253.  
  254.  
  255. TAGS
  256.      The first form of annotation in text widgets is  a  tag.   A
  257.      tag  is a textual string that is associated with some of the
  258.  
  259.  
  260.  
  261. Tk                                                              4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. text(n)                    Tk Commands
  269.  
  270.  
  271.  
  272.      characters in a text.  There may be any number of tags asso-
  273.      ciated  with  characters in a text.  Each tag may refer to a
  274.      single character, a range of characters, or  several  ranges
  275.      of  characters.  An individual character may have any number
  276.      of tags associated with it.
  277.  
  278.      A priority order is defined among tags, and  this  order  is
  279.      used  in  implementing  some  of  the  tag-related functions
  280.      described below.  When a tag is defined (by  associating  it
  281.      with  characters  or  setting its display options or binding
  282.      commands to it), it is given  a  priority  higher  than  any
  283.      existing  tag.   The priority order of tags may be redefined
  284.      using the ``_p_a_t_h_N_a_m_e tag raise'' and ``_p_a_t_h_N_a_m_e tag  lower''
  285.      widget commands.
  286.  
  287.      Tags serve three purposes in text widgets.  First, they con-
  288.      trol  the  way  information  is displayed on the screen.  By
  289.      default, characters are displayed as determined by the back-
  290.      ground,  font,  and  foreground options for the text widget.
  291.      However, display options may be associated  with  individual
  292.      tags  using  the  ``_p_a_t_h_N_a_m_e tag configure'' widget command.
  293.      If a character has been tagged,  then  the  display  options
  294.      associated  with the tag override the default display style.
  295.      The following options are currently supported for tags:
  296.  
  297.      -background _c_o_l_o_r
  298.           _C_o_l_o_r specifies the background color to use for charac-
  299.           ters  associated  with the tag.  It may have any of the
  300.           forms accepted by Tk_GetColor.
  301.  
  302.      -bgstipple _b_i_t_m_a_p
  303.           _B_i_t_m_a_p specifies a bitmap that is  used  as  a  stipple
  304.           pattern  for  the  background.   It may have any of the
  305.           forms accepted by Tk_GetBitmap.  If _b_i_t_m_a_p hasn't  been
  306.           specified,  or  if  it is specified as an empty string,
  307.           then a solid fill will be used for the background.
  308.  
  309.      -borderwidth _p_i_x_e_l_s
  310.           _P_i_x_e_l_s specifies the width of  a  3-D  border  to  draw
  311.           around  the  background.   It may have any of the forms
  312.           accepted by Tk_GetPixels.  This option is used in  con-
  313.           junction  with the -relief option to give a 3-D appear-
  314.           ance to the background for characters;  it  is  ignored
  315.           unless the -background option has been set for the tag.
  316.  
  317.      -fgstipple _b_i_t_m_a_p
  318.           _B_i_t_m_a_p specifies a bitmap that is  used  as  a  stipple
  319.           pattern when drawing text and other foreground informa-
  320.           tion such as underlines.  It may have any of the  forms
  321.           accepted by Tk_GetBitmap.  If _b_i_t_m_a_p hasn't been speci-
  322.           fied, or if it is specified as an empty string, then  a
  323.           solid fill will be used.
  324.  
  325.  
  326.  
  327. Tk                                                              5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. text(n)                    Tk Commands
  335.  
  336.  
  337.  
  338.      -font _f_o_n_t_N_a_m_e
  339.           _F_o_n_t_N_a_m_e is the name of a font to use for drawing char-
  340.           acters.   It  may  have  any  of  the forms accepted by
  341.           Tk_GetFontStruct.
  342.  
  343.      -foreground _c_o_l_o_r
  344.           _C_o_l_o_r specifies the color to use when drawing text  and
  345.           other  foreground  information  such as underlines.  It
  346.           may have any of the forms accepted by Tk_GetColor.
  347.  
  348.      -relief _r_e_l_i_e_f
  349.           _R_e_l_i_e_f _s_p_e_c_i_f_i_e_s _t_h_e _3-_D  _r_e_l_i_e_f  _t_o  _u_s_e  _f_o_r  _d_r_a_w_i_n_g
  350.           _b_a_c_k_g_r_o_u_n_d_s,   _i_n   _a_n_y   _o_f   _t_h_e  _f_o_r_m_s  _a_c_c_e_p_t_e_d  _b_y
  351.           Tk_GetRelief.  This option is used in conjunction  with
  352.           the -borderwidth option to give a 3-D appearance to the
  353.           background for characters; it  is  ignored  unless  the
  354.           -background option has been set for the tag.
  355.  
  356.      -underline _b_o_o_l_e_a_n
  357.           _B_o_o_l_e_a_n specifies whether or not to draw  an  underline
  358.           underneath  characters.   It  may have any of the forms
  359.           accepted by Tk_GetBoolean.
  360.  
  361.      If a character has several tags associated with it,  and  if
  362.      their  display  options  conflict,  then  the options of the
  363.      highest priority tag are  used.   If  a  particular  display
  364.      option  hasn't been specified for a particular tag, or if it
  365.      is specified as an empty string, then that option will never
  366.      be  used;   the next-highest-priority tag's option will used
  367.      instead.  If no tag specifies a particular display  optionl,
  368.      then the default style for the widget will be used.
  369.  
  370.      The second purpose for tags  is  event  bindings.   You  can
  371.      associate  bindings  with a tag in much the same way you can
  372.      associate bindings with a widget class:  whenever particular
  373.      X events occur on characters with the given tag, a given Tcl
  374.      command will be executed.  Tag bindings can be used to  give
  375.      behaviors  to ranges of characters; among other things, this
  376.      allows  hypertext-like  features  to  be  implemented.   For
  377.      details,  see the description of the tag bind widget command
  378.      below.
  379.  
  380.      The third use for tags is in managing  the  selection.   See
  381.      THE SELECTION below.
  382.  
  383.  
  384. MARKS
  385.      The second form of annotation in text  widgets  is  a  mark.
  386.      Marks  are used for remembering particular places in a text.
  387.      They are something like tags, in that they  have  names  and
  388.      they  refer  to places in the file, but a mark isn't associ-
  389.      ated  with  particular  characters.   Instead,  a  mark   is
  390.  
  391.  
  392.  
  393. Tk                                                              6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. text(n)                    Tk Commands
  401.  
  402.  
  403.  
  404.      associated with the gap between two characters.  Only a sin-
  405.      gle position may be associated with  a  mark  at  any  given
  406.      time.   If the characters around a mark are deleted the mark
  407.      will still remain;  it will just have new  neighbor  charac-
  408.      ters.   In  contrast, if the characters containing a tag are
  409.      deleted then the tag will no longer have an association with
  410.      characters  in  the file.  Marks may be manipulated with the
  411.      ``_p_a_t_h_N_a_m_e mark'' widget command, and  their  current  loca-
  412.      tions  may  be determined by using the mark name as an index
  413.      in widget commands.
  414.  
  415.      The name space for marks is different from  that  for  tags:
  416.      the  same  name  may  be used for both a mark and a tag, but
  417.      they will refer to different things.
  418.  
  419.      Two marks have special significance.  First, the mark insert
  420.      is  associated with the insertion cursor, as described under
  421.      THE INSERTION CURSOR below.  Second,  the  mark  current  is
  422.      associated  with  the  character closest to the mouse and is
  423.      adjusted automatically to track the mouse position  and  any
  424.      changes  to  the text in the widget (one exception:  current
  425.      is not updated in response to mouse motions if a mouse  but-
  426.      ton  is  down;   the update will be deferred until all mouse
  427.      buttons have been released).  Neither of these special marks
  428.      may be unset.
  429.  
  430.  
  431. WINDOWS
  432.      The third form of annotation in text widgets  is  a  window.
  433.      Window support isn't implemented yet, but when it is it will
  434.      be described here.
  435.  
  436.  
  437. THE SELECTION
  438.      Text widgets support the standard  X  selection.   Selection
  439.      support  is  implemented  via  tags.  If the exportSelection
  440.      option for the text widget is true then the sel tag will  be
  441.      associated with the selection:
  442.  
  443.      [1]  Whenever characters are tagged with sel the text widget
  444.           will claim ownership of the selection.
  445.  
  446.      [2]  Attempts to retrieve the selection will be serviced  by
  447.           the  text  widget, returning all the charaters with the
  448.           sel tag.
  449.  
  450.      [3]  If the selection is claimed away by another application
  451.           or  by another window within this application, then the
  452.           sel tag will be removed  from  all  characters  in  the
  453.           text.
  454.  
  455.  
  456.  
  457.  
  458.  
  459. Tk                                                              7
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. text(n)                    Tk Commands
  467.  
  468.  
  469.  
  470.      The sel tag is automatically defined when a text  widget  is
  471.      created,  and  it may not be deleted with the ``_p_a_t_h_N_a_m_e tag
  472.      delete'' widget command.  Furthermore, the selectBackground,
  473.      selectBorderWidth, and selectForeground options for the text
  474.      widget are tied to the -background, -borderwidth, and -fore-
  475.      ground  options  for  the  sel  tag:  changes in either will
  476.      automatically be reflected in the other.
  477.  
  478.  
  479. THE INSERTION CURSOR
  480.      The mark named insert has special significance in text widg-
  481.      ets.   It  is  defined  automatically  when a text widget is
  482.      created and it may not be unset  with  the  ``_p_a_t_h_N_a_m_e  mark
  483.      unset''  widget  command.   The  insert  mark represents the
  484.      position of the insertion cursor, and the  insertion  cursor
  485.      will  automatically be drawn at this point whenever the text
  486.      widget has the input focus.
  487.  
  488.  
  489. WIDGET COMMAND
  490.      The text command creates a new Tcl command whose name is the
  491.      same  as  the  path name of the text's window.  This command
  492.      may be used to invoke various operations on the widget.   It
  493.      has the following general form:
  494.  
  495.           _p_a_t_h_N_a_m_e _o_p_t_i_o_n ?_a_r_g _a_r_g ...?
  496.  
  497.      _P_a_t_h_N_a_m_e is the name of the command, which is  the  same  as
  498.      the  text widget's path name.  _O_p_t_i_o_n and the _a_r_gs determine
  499.      the exact behavior of the command.  The  following  commands
  500.      are possible for text widgets:
  501.  
  502.      _p_a_t_h_N_a_m_e compare _i_n_d_e_x_1 _o_p _i_n_d_e_x_2
  503.           Compares the indices given by _i_n_d_e_x_1 and _i_n_d_e_x_2 accord-
  504.           ing to the relational operator given by _o_p, and returns
  505.           1 if the relationship is satisfied and 0 if  it  isn't.
  506.           _O_p  must  be  one of the operators <, <=, ==, >=, >, or
  507.           !=.  If _o_p is == then 1 is returned if the two  indices
  508.           refer  to  the  same  character,  if  _o_p is < then 1 is
  509.           returned if _i_n_d_e_x_1 refers to an  earlier  character  in
  510.           the text than _i_n_d_e_x_2, and so on.
  511.  
  512.      _p_a_t_h_N_a_m_e configure ?_o_p_t_i_o_n? ?_v_a_l_u_e _o_p_t_i_o_n _v_a_l_u_e ...?
  513.           Query  or  modify  the  configuration  options  of  the
  514.           widget.   If  no  _o_p_t_i_o_n  is  specified, returns a list
  515.           describing all of the available  options  for  _p_a_t_h_N_a_m_e
  516.           (see  Tk_ConfigureInfo for information on the format of
  517.           this list).  If _o_p_t_i_o_n is specified with no _v_a_l_u_e, then
  518.           the  command  returns  a  list describing the one named
  519.           option (this list will be identical to the  correspond-
  520.           ing  sublist  of  the  value  returned  if no _o_p_t_i_o_n is
  521.           specified).  If one  or  more  _o_p_t_i_o_n-_v_a_l_u_e  pairs  are
  522.           specified,  then  the command modifies the given widget
  523.  
  524.  
  525.  
  526. Tk                                                              8
  527.  
  528.  
  529.  
  530.  
  531.  
  532. text(n)                    Tk Commands
  533.  
  534.  
  535.  
  536.           option(s) to have the given value(s);  in this case the
  537.           command  returns  an empty string.  _O_p_t_i_o_n may have any
  538.           of the values accepted by the text command.
  539.  
  540.      _p_a_t_h_N_a_m_e debug ?_b_o_o_l_e_a_n?
  541.           If _b_o_o_l_e_a_n is specified, then it must have one  of  the
  542.           true  or  false  values accepted by Tcl_GetBoolean.  If
  543.           the value is  a  true  one  then  internal  consistency
  544.           checks  will be turned on in the B-tree code associated
  545.           with text widgets.  If _b_o_o_l_e_a_n has a false  value  then
  546.           the  debugging  checks  will  be turned off.  In either
  547.           case the command returns an empty string.   If  _b_o_o_l_e_a_n
  548.           is  not specified then the command returns on or off to
  549.           indicate whether or not debugging is turned on.   There
  550.           is  a  single debugging switch shared by all text widg-
  551.           ets:  turning debugging on or off in any  widget  turns
  552.           it  on  or off for all widgets.  For widgets with large
  553.           amounts of text, the consistency  checks  may  cause  a
  554.           noticeable slow-down.
  555.  
  556.      _p_a_t_h_N_a_m_e delete _i_n_d_e_x_1 ?_i_n_d_e_x_2?
  557.           Delete a range of characters from the  text.   If  both
  558.           _i_n_d_e_x_1  and  _i_n_d_e_x_2  are specified, then delete all the
  559.           characters starting with the one given  by  _i_n_d_e_x_1  and
  560.           stopping  just  before  _i_n_d_e_x_2  (i.e.  the character at
  561.           _i_n_d_e_x_2 is not deleted).  If _i_n_d_e_x_2  doesn't  specify  a
  562.           position  later in the text than _i_n_d_e_x_1 then no charac-
  563.           ters are deleted.  If _i_n_d_e_x_2 isn't specified  then  the
  564.           single  character  at  _i_n_d_e_x_1  is  deleted.   It is not
  565.           allowable to delete characters  in  a  way  that  would
  566.           leave the text without a newline as the last character.
  567.           The command returns an empty string.
  568.  
  569.      _p_a_t_h_N_a_m_e get _i_n_d_e_x_1 ?_i_n_d_e_x_2?
  570.           Return a range of characters from the text.  The return
  571.           value  will  be all the characters in the text starting
  572.           with the one whose index  is  _i_n_d_e_x_1  and  ending  just
  573.           before  the one whose index is _i_n_d_e_x_2 (the character at
  574.           _i_n_d_e_x_2 will not be returned).   If  _i_n_d_e_x_2  is  omitted
  575.           then  the  single  character at _i_n_d_e_x_1 is returned.  If
  576.           there are no characters in the  specified  range  (e.g.
  577.           _i_n_d_e_x_1  is  past  the end of the file or _i_n_d_e_x_2 is less
  578.           than or equal  to  _i_n_d_e_x_1)  then  an  empty  string  is
  579.           returned.
  580.  
  581.      _p_a_t_h_N_a_m_e index _i_n_d_e_x
  582.           Returns the position corresponding to _i_n_d_e_x in the form
  583.           _l_i_n_e._c_h_a_r where _l_i_n_e is the line number and _c_h_a_r is the
  584.           character number.  _I_n_d_e_x may  have  any  of  the  forms
  585.           described under INDICES above.
  586.  
  587.      _p_a_t_h_N_a_m_e insert _i_n_d_e_x _c_h_a_r_s
  588.  
  589.  
  590.  
  591. Tk                                                              9
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. text(n)                    Tk Commands
  599.  
  600.  
  601.  
  602.           Inserts _c_h_a_r_s into the text just before  the  character
  603.           at _i_n_d_e_x and returns an empty string.  It is not possi-
  604.           ble to insert characters after the last newline of  the
  605.           text.
  606.  
  607.      _p_a_t_h_N_a_m_e mark _o_p_t_i_o_n ?_a_r_g _a_r_g ...?
  608.           This command is used to manipulate  marks.   The  exact
  609.           behavior  of the command depends on the _o_p_t_i_o_n argument
  610.           that follows the mark argument.  The following forms of
  611.           the command are currently supported:
  612.  
  613.           _p_a_t_h_N_a_m_e mark names
  614.                Returns a list whose elements are the names of all
  615.                the marks that are currently set.
  616.  
  617.           _p_a_t_h_N_a_m_e mark set _m_a_r_k_N_a_m_e _i_n_d_e_x
  618.                Sets the mark named _m_a_r_k_N_a_m_e to  a  position  just
  619.                before   the  character  at  _i_n_d_e_x.   If  _m_a_r_k_N_a_m_e
  620.                already exists, it is moved from its old position;
  621.                if  it doesn't exist, a new mark is created.  This
  622.                command returns an empty string.
  623.  
  624.           _p_a_t_h_N_a_m_e mark unset _m_a_r_k_N_a_m_e ?_m_a_r_k_N_a_m_e _m_a_r_k_N_a_m_e ...?
  625.                Remove the mark corresponding to each of the _m_a_r_k_-
  626.                _N_a_m_e  arguments.   The  removed  marks will not be
  627.                usable in indices and  will  not  be  returned  by
  628.                future  calls  to  ``_p_a_t_h_N_a_m_e  mark names''.  This
  629.                command returns an empty string.
  630.  
  631.      _p_a_t_h_N_a_m_e scan _o_p_t_i_o_n _a_r_g_s
  632.           This command is used to implement  scanning  on  texts.
  633.           It has two forms, depending on _o_p_t_i_o_n:
  634.  
  635.           _p_a_t_h_N_a_m_e scan mark _y
  636.                Records _y and the current view in the text window;
  637.                used  in  conjunction  with later scan dragto com-
  638.                mands.  Typically this command is associated  with
  639.                a mouse button press in the widget.  It returns an
  640.                empty string.
  641.  
  642.           _p_a_t_h_N_a_m_e scan dragto _y
  643.                This command computes the difference between its _y
  644.                argument  and the _y argument to the last scan mark
  645.                command for the widget.  It then adjusts the  view
  646.                up  or  down  by  10  times  the  difference in y-
  647.                coordinates.  This command is typically associated
  648.                with mouse motion events in the widget, to produce
  649.                the effect of dragging  the  text  at  high  speed
  650.                through  the window.  The return value is an empty
  651.                string.
  652.  
  653.      _p_a_t_h_N_a_m_e tag _o_p_t_i_o_n ?_a_r_g _a_r_g ...?
  654.  
  655.  
  656.  
  657. Tk                                                             10
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. text(n)                    Tk Commands
  665.  
  666.  
  667.  
  668.           This command is used to  manipulate  tags.   The  exact
  669.           behavior  of the command depends on the _o_p_t_i_o_n argument
  670.           that follows the tag argument.  The following forms  of
  671.           the command are currently supported:
  672.  
  673.           _p_a_t_h_N_a_m_e tag add _t_a_g_N_a_m_e _i_n_d_e_x_1 ?_i_n_d_e_x_2?
  674.                Associate the tag _t_a_g_N_a_m_e with all of the  charac-
  675.                ters  starting  with _i_n_d_e_x_1 and ending just before
  676.                _i_n_d_e_x_2 (the character at _i_n_d_e_x_2 isn't tagged).  If
  677.                _i_n_d_e_x_2  is  omitted  then  the single character at
  678.                _i_n_d_e_x_1 is tagged.  If there are no  characters  in
  679.                the  specified  range (e.g. _i_n_d_e_x_1 is past the end
  680.                of the file or _i_n_d_e_x_2 is less  than  or  equal  to
  681.                _i_n_d_e_x_1) then the command has no effect.  This com-
  682.                mand returns an empty string.
  683.  
  684.           _p_a_t_h_N_a_m_e tag bind _t_a_g_N_a_m_e ?_s_e_q_u_e_n_c_e? ?_c_o_m_m_a_n_d?
  685.                This command associates _c_o_m_m_a_n_d with the tag given
  686.                by  _t_a_g_N_a_m_e.  Whenever the event sequence given by
  687.                _s_e_q_u_e_n_c_e occurs for  a  character  that  has  been
  688.                tagged  with _t_a_g_N_a_m_e, the command will be invoked.
  689.                This widget command is similar to the bind command
  690.                except  that  it  operates on characters in a text
  691.                rather than entire widgets.  See the  bind  manual
  692.                entry  for  complete  details  on  the  syntax  of
  693.                _s_e_q_u_e_n_c_e and the substitutions performed  on  _c_o_m_-
  694.                _m_a_n_d  before  invoking  it.   If all arguments are
  695.                specified then a new binding is created, replacing
  696.                any  existing  binding  for  the same _s_e_q_u_e_n_c_e and
  697.                _t_a_g_N_a_m_e (if the  first  character  of  _c_o_m_m_a_n_d  is
  698.                ``+''  then  _c_o_m_m_a_n_d  augments an existing binding
  699.                rather than  replacing  it).   In  this  case  the
  700.                return  value  is  an empty string.  If _c_o_m_m_a_n_d is
  701.                omitted then the command returns the _c_o_m_m_a_n_d asso-
  702.                ciated  with _t_a_g_N_a_m_e and _s_e_q_u_e_n_c_e (an error occurs
  703.                if there is no such binding).  If both _c_o_m_m_a_n_d and
  704.                _s_e_q_u_e_n_c_e  are  omitted  then the command returns a
  705.                list of all the sequences for which bindings  have
  706.                been defined for _t_a_g_N_a_m_e.
  707.  
  708.                The only events for which bindings may  be  speci-
  709.                fied  are those related to the mouse and keyboard,
  710.                such as Enter,  Leave,  ButtonPress,  Motion,  and
  711.                KeyPress.   Event  bindings  for a text widget use
  712.                the current  mark  described  under  MARKS  above.
  713.                Enter  events  trigger  for  a  character  when it
  714.                becomes the current character  (i.e.  the  current
  715.                mark  moves  to  just in front of that character).
  716.                Leave events  trigger  for  a  character  when  it
  717.                ceases  to  be  the current item (i.e. the current
  718.                mark moves away from that character, or the  char-
  719.                acter  is  deleted).   These  events are different
  720.  
  721.  
  722.  
  723. Tk                                                             11
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. text(n)                    Tk Commands
  731.  
  732.  
  733.  
  734.                than Enter and Leave events  for  windows.   Mouse
  735.                and  keyboard  events  are directed to the current
  736.                character.
  737.  
  738.                It is possible for the current character  to  have
  739.                multiple  tags,  and  for  each  of them to have a
  740.                binding for a  particular  event  sequence.   When
  741.                this occurs, the binding from the highest priority
  742.                tag is used.  If a particular tag doesn't  have  a
  743.                binding  that  matches  an  event, then the tag is
  744.                ignored and  tags  with  lower  priority  will  be
  745.                checked.
  746.  
  747.                If bindings are created for the widget as a  whole
  748.                using  the  bind command, then those bindings will
  749.                supplement the tag bindings.  This  means  that  a
  750.                single  event can trigger two Tcl scripts, one for
  751.                a widget-level binding and  one  for  a  tag-level
  752.                binding.
  753.  
  754.           _v_a_l_u_e ...?
  755.           _p_a_t_h_N_a_m_e tag  configure  _t_a_g_N_a_m_e  ?_o_p_t_i_o_n?  ?_v_a_l_u_e?  ?_o_p_t_i_o_n
  756.                This  command  is  similar to the configure widget
  757.                command except that it modifies options associated
  758.                with the tag given by _t_a_g_N_a_m_e instead of modifying
  759.                options for the overall text widget.  If no _o_p_t_i_o_n
  760.                is  specified, the command returns a list describ-
  761.                ing all of the available options for _t_a_g_N_a_m_e  (see
  762.                Tk_ConfigureInfo  for information on the format of
  763.                this list).  If _o_p_t_i_o_n is specified with no _v_a_l_u_e,
  764.                then the command returns a list describing the one
  765.                named option (this list will be identical  to  the
  766.                corresponding  sublist of the value returned if no
  767.                _o_p_t_i_o_n is specified).  If one or more _o_p_t_i_o_n-_v_a_l_u_e
  768.                pairs are specified, then the command modifies the
  769.                given option(s) to have the given value(s) in _t_a_g_-
  770.                _N_a_m_e;  in  this  case the command returns an empty
  771.                string.  See TAGS above for details on the options
  772.                available for tags.
  773.  
  774.           _p_a_t_h_N_a_m_e tag delete _t_a_g_N_a_m_e ?_t_a_g_N_a_m_e ...?
  775.                Deletes all tag information for each of  the  _t_a_g_-
  776.                _N_a_m_e arguments.  The command removes the tags from
  777.                all characters in the file and  also  deletes  any
  778.                other  information  associated with the tags, such
  779.                as bindings and display information.  The  command
  780.                returns an empty string.
  781.  
  782.           _p_a_t_h_N_a_m_etag lower _t_a_g_N_a_m_e ?_b_e_l_o_w_T_h_i_s?
  783.                Changes the priority of tag _t_a_g_N_a_m_e so that it  is
  784.                just  lower in priority than the tag whose name is
  785.                _b_e_l_o_w_T_h_i_s.   If   _b_e_l_o_w_T_h_i_s   is   omitted,   then
  786.  
  787.  
  788.  
  789. Tk                                                             12
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. text(n)                    Tk Commands
  797.  
  798.  
  799.  
  800.                _t_a_g_N_a_m_e's  priority  is  changed to make it lowest
  801.                priority of all tags.
  802.  
  803.           _p_a_t_h_N_a_m_e tag names ?_i_n_d_e_x?
  804.                Returns a list whose elements are the names of all
  805.                the tags that are active at the character position
  806.                given by _i_n_d_e_x.  If _i_n_d_e_x  is  omitted,  then  the
  807.                return  value  will  describe all of the tags that
  808.                exist for the text (this includes  all  tags  that
  809.                have  been named in a ``_p_a_t_h_N_a_m_e tag'' widget com-
  810.                mand but haven't been deleted by a ``_p_a_t_h_N_a_m_e  tag
  811.                delete'' widget command, even if no characters are
  812.                currently marked with the tag).  The list will  be
  813.                sorted  in  order  from lowest priority to highest
  814.                priority.
  815.  
  816.           _p_a_t_h_N_a_m_e tag nextrange _t_a_g_N_a_m_e _i_n_d_e_x_1 ?_i_n_d_e_x_2?
  817.                This command searches the  text  for  a  range  of
  818.                characters  tagged  with  _t_a_g_N_a_m_e  where the first
  819.                character of the range  is  no  earlier  than  the
  820.                character  at _i_n_d_e_x_1 and no later than the charac-
  821.                ter just before _i_n_d_e_x_2 (a range starting at _i_n_d_e_x_2
  822.                will  not  be  considered).   If  several matching
  823.                ranges  exist,  the  first  one  is  chosen.   The
  824.                command's  return  value  is a list containing two
  825.                elements, which are the index of the first charac-
  826.                ter  of  the  range and the index of the character
  827.                just after the last  one  in  the  range.   If  no
  828.                matching  range  is found then the return value is
  829.                an empty string.  If _i_n_d_e_x_2 is not given  then  it
  830.                defaults to the end of the text.
  831.  
  832.           _p_a_t_h_N_a_m_etag raise _t_a_g_N_a_m_e ?_a_b_o_v_e_T_h_i_s?
  833.                Changes the priority of tag _t_a_g_N_a_m_e so that it  is
  834.                just higher in priority than the tag whose name is
  835.                _a_b_o_v_e_T_h_i_s.   If   _a_b_o_v_e_T_h_i_s   is   omitted,   then
  836.                _t_a_g_N_a_m_e's  priority  is changed to make it highest
  837.                priority of all tags.
  838.  
  839.           _p_a_t_h_N_a_m_e tag ranges _t_a_g_N_a_m_e
  840.                Returns a list describing all  of  the  ranges  of
  841.                text  that  have  been  tagged  with _t_a_g_N_a_m_e.  The
  842.                first two elements of the list describe the  first
  843.                tagged  range  in  the text, the next two elements
  844.                describe the second range, and so on.   The  first
  845.                element  of  each  pair  contains the index of the
  846.                first character of the range, and the second  ele-
  847.                ment of the pair contains the index of the charac-
  848.                ter just after the last  one  in  the  range.   If
  849.                there  are  no  characters tagged with _t_a_g then an
  850.                empty string is returned.
  851.  
  852.  
  853.  
  854.  
  855. Tk                                                             13
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. text(n)                    Tk Commands
  863.  
  864.  
  865.  
  866.           _p_a_t_h_N_a_m_e tag remove _t_a_g_N_a_m_e _i_n_d_e_x_1 ?_i_n_d_e_x_2?
  867.                Remove the tag _t_a_g_N_a_m_e from all of the  characters
  868.                starting  at  _i_n_d_e_x_1 and ending just before _i_n_d_e_x_2
  869.                (the character  at  _i_n_d_e_x_2  isn't  affected).   If
  870.                _i_n_d_e_x_2  is  omitted  then  the single character at
  871.                _i_n_d_e_x_1 is untagged.  If there are no characters in
  872.                the  specified  range (e.g. _i_n_d_e_x_1 is past the end
  873.                of the file or _i_n_d_e_x_2 is less  than  or  equal  to
  874.                _i_n_d_e_x_1) then the command has no effect.  This com-
  875.                mand returns an empty string.
  876.  
  877.      _p_a_t_h_N_a_m_e yview ?-pickplace? _w_h_a_t
  878.           This command changes the view in the widget's window so
  879.           that  the  line given by _w_h_a_t is visible in the window.
  880.           _W_h_a_t may be either an absolute  line  number,  where  0
  881.           corresponds  to the first line of the file, or an index
  882.           with any of the forms described  under  INDICES  above.
  883.           The  first  form  (absolute line number) is used in the
  884.           commands issued by scrollbars to control  the  widget's
  885.           view.   If  the  -pickplace option isn't specified then
  886.           _w_h_a_t will appear at the top of the window.   If  -pick-
  887.           place  is  specified then the widget chooses where _w_h_a_t
  888.           appears in the window:
  889.  
  890.           [1]  If _w_h_a_t is already visible somewhere in the window
  891.                then the command does nothing.
  892.  
  893.           [2]  If _w_h_a_t is only a few lines off-screen  above  the
  894.                window  then  it  will be positioned at the top of
  895.                the window.
  896.  
  897.           [3]  If _w_h_a_t is only a few lines off-screen  below  the
  898.                window then it will be positioned at the bottom of
  899.                the window.
  900.  
  901.           [4]  Otherwise, _w_h_a_t will be centered in the window.
  902.  
  903.           The -pickplace option is typically used after inserting
  904.           text  to  make  sure that the insertion cursor is still
  905.           visible on the screen.  This command returns  an  empty
  906.           string.
  907.  
  908.  
  909. BINDINGS
  910.      Tk automatically creates class bindings for texts that  give
  911.      them the following default behavior:
  912.  
  913.      [1]  Pressing mouse button 1 in an text positions the inser-
  914.           tion  cursor  just  before the character underneath the
  915.           mouse cursor and sets the input focus to this widget.
  916.  
  917.      [2]  Dragging with mouse button 1 strokes  out  a  selection
  918.  
  919.  
  920.  
  921. Tk                                                             14
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. text(n)                    Tk Commands
  929.  
  930.  
  931.  
  932.           between  the  insertion  cursor and the character under
  933.           the mouse.
  934.  
  935.      [3]  If you double-press mouse button 1 then the word  under
  936.           the mouse cursor will be selected, the insertion cursor
  937.           will be positioned at the beginning of  the  word,  and
  938.           dragging  the  mouse  will stroke out a selection whole
  939.           words at a time.
  940.  
  941.      [4]  If you triple-press mouse button 1 then the line  under
  942.           the mouse cursor will be selected, the insertion cursor
  943.           will be positioned at the beginning of  the  line,  and
  944.           dragging  the  mouse  will stroke out a selection whole
  945.           line at a time.
  946.  
  947.      [5]  The ends of the selection can be adjusted  by  dragging
  948.           with  mouse button 1 while the shift key is down;  this
  949.           will adjust the end of the selection that  was  nearest
  950.           to  the mouse cursor when button 1 was pressed.  If the
  951.           selection was made in word or line mode then it will be
  952.           adjusted in this same mode.
  953.  
  954.      [6]  The view in the text can be adjusted by  dragging  with
  955.           mouse button 2.
  956.  
  957.      [7]  If the input focus is in a text widget  and  characters
  958.           are  typed on the keyboard, the characters are inserted
  959.           just before the insertion cursor.
  960.  
  961.      [8]  Control+h and the Backspace and Delete keys  erase  the
  962.           character just before the insertion cursor.
  963.  
  964.      [9]  Control+v inserts the current selection just before the
  965.           insertion cursor.
  966.  
  967.      [10] Control+d deletes the selected  characters;   an  error
  968.           occurs if the selection is not in this widget.
  969.  
  970.      If the text is disabled using the  state  option,  then  the
  971.      text's  view  can still be adjusted and text in the text can
  972.      still be selected, but no insertion cursor will be displayed
  973.      and no text modifications will take place.
  974.  
  975.      The behavior of texts can be changed by defining  new  bind-
  976.      ings for individual widgets or by redefining the class bind-
  977.      ings.
  978.  
  979.  
  980. PERFORMANCE ISSUES
  981.      Text widgets should run efficiently under a variety of  con-
  982.      ditions.   The  text  widget  uses  about  2-3 bytes of main
  983.      memory for each byte of text, so texts containing a megabyte
  984.  
  985.  
  986.  
  987. Tk                                                             15
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. text(n)                    Tk Commands
  995.  
  996.  
  997.  
  998.      or  more  should be practical on most workstations.  Text is
  999.      represented internally with a modified B-tree structure that
  1000.      makes operations relatively efficient even with large texts.
  1001.      Tags are included in the B-tree  structure  in  a  way  that
  1002.      allows  tags  to  span  large  ranges  or have many disjoint
  1003.      smaller ranges without loss of efficiency.  Marks  are  also
  1004.      implemented  in  a  way  that allows large numbers of marks.
  1005.      The only known mode of operation where a text widget may not
  1006.      run  efficiently  is  if  it has a very large number of dif-
  1007.      ferent tags.  Hundreds of tags should be  fine,  or  even  a
  1008.      thousand, but tens of thousands of tags will make texts con-
  1009.      sume a lot of memory and run slowly.
  1010.  
  1011.  
  1012. KEYWORDS
  1013.      text, widget
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053. Tk                                                             16
  1054.  
  1055.  
  1056.  
  1057.